905. Sort Array By Parity - LeetCode Solution


Array

Python Code:

class Solution:
    def sortArrayByParity(self, A: List[int]) -> List[int]:
        g = len(A)-1
        
        k = 0
        
        while g!=k:
            if A[k]%2==0:
                k+=1
            else:
                A[k], A[g] = A[g], A[k]
                g-=1
            
        return A
                
                
            
        


Comments

Submit
0 Comments
More Questions

AND path in a binary tree
Factorial equations
Removal of vertices
Happy segments
Cyclic shifts
Zoos
Build a graph
Almost correct bracket sequence
Count of integers
Differences of the permutations
Doctor's Secret
Back to School
I am Easy
Teddy and Tweety
Partitioning binary strings
Special sets
Smallest chosen word
Going to office
Color the boxes
Missing numbers
Maximum sum
13 Reasons Why
Friend's Relationship
Health of a person
Divisibility
A. Movement
Numbers in a matrix
Sequences
Split houses
Divisible